package com.share.example.stock.web;

import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.example.stock.model.rsp.StockDayPricePageReq;
import com.share.example.stock.service.IStockDayPriceService;
import com.share.example.stock.service.ITradeDateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 目标地址: http://vip.stock.finance.sina.com.cn/mkt/#hs_s
 * 描述: 中国股票指数数据, 注意该股票指数指新浪提供的国内股票指数
 * 限量: 单次返回所有指数的实时行情数据  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-06-10
 */
@RestController
@RequestMapping("/stockdayprice")
public class StockDayPriceController {
    @Autowired
    private ITradeDateService iTradeDateService;
    @Autowired
    private IStockDayPriceService iStockDayPriceService;

    @RequestMapping("/pageList")
    public Result pageList(StockDayPricePageReq req) {
        Page page = iStockDayPriceService.pageList(req);
        return Result.success(page);
    }

    @RequestMapping("/down")
    public Result downCurDay() {
        //非工作日直接跳过
        if (!iTradeDateService.isTradeDay(new Date())) {
            return Result.failure("非交易日直接退出");
        }

        Object obj = iStockDayPriceService.downToDay();
        return Result.success(obj);
    }
}
